<?php

namespace weapp\ErxClose\behavior\home;


/**
 * 行为扩展
 */
class ErxCloseBehavior
{
    protected static $actionName;
    protected static $controllerName;
    protected static $moduleName;
    protected static $method;

    /**
     * 构造方法
     * @param Request $request Request对象
     * @access public
     */
    public function __construct()
    {
        !isset(self::$moduleName) && self::$moduleName = request()->module();
        !isset(self::$controllerName) && self::$controllerName = request()->controller();
        !isset(self::$actionName) && self::$actionName = request()->action();
        !isset(self::$method) && self::$method = strtoupper(request()->method());

        $this->logic = new \weapp\ErxClose\logic\ErxCloseLogic;            
    }

    /**
     * 模块初始化
     * @param array $params 传入参数
     * @access public
     */
    public function moduleInit(&$params)
    { 
        
    }

    /**
     * 操作开始执行
     * @param array $params 传入参数
     * @access public
     */
    public function actionBegin(&$params)
    {
        $data =  \think\Db::name('weapp')->where('code','ErxClose')->field('data')->find();
        $row = json_decode($data['data'], true);          
        if (!$row) {            
            return true;
        }                        
        // 全站
        if($row['is_open'] ==1){
            if($this->logic->todo($row)==false){                 
                 $this->logic->setCode($row);
            }
        }       
        if($row['is_open']==2 && self::$controllerName =='Index' && self::$actionName=='index'){    
           if($this->logic->todo($row)==false){                  
                $this->logic->setCode($row);
           }                 
        }
    }

    /**
     * 视图内容过滤
     * @param array $params 传入参数
     * @access public
     */
    public function viewFilter(&$params)
    {               
    }
    /**
     * 应用结束
     * @param array $params 传入参数
     * @access public
     */
    public function appEnd(&$params)
    {

    }    
}